<?php
	
	class Search extends CI_Controller{
		
		function __construct(){
			parent::__construct();
			$this->load->model(array('search_model'));
			$this->load->library(array('Data_solr', 'pagination'));
			$this->load->helper(array('url'));
		}
		
		function index($keyword = NULL, $page = 1){ //index($keyword = NULL, $filter, $page = 1)
			# Get keywords
			
			if($keyword == "") {
				redirect();
			}else {
				$keyword 	= preg_replace('/[\s\?\%20]+/is','+',$keyword);
				$keyword 	= preg_replace('/[\:\?\&\<\>\#\'\"\+]+/is',' ',$keyword);
			}

			$limit		=	5;
			$offset		=	($page - 1)*$limit;
			$queries 	= 	array();
			$queries[0] = 	$keyword;
			$res		=	$this->data_solr->search($queries, $offset, $limit);
			//$res		=	$this->data_solr->search($queries, $filter, $offset, $limit);
			$url 		= 	base_url()."search/".$keyword;
			$total		=	ceil($res['total_num']/$limit); 
  			$conf = array(
		  					'total_rows'		=>	$total,
		  					'cur_page'			=>	$page,
		  					'base_url'			=>	$url,
		  					'show_num'			=>	'yes',
		  					'show_total' 		=>	'no',
		  					'show_first_last'	=>	'yes',
		  					'prev_class'		=>	'pic',
		  					'next_class'		=>	'pic',
		  					'next_link'			=>	'Next >>',
		  					'prev_link'			=>	'<< Prev'
		  				 );
  			$this->pagination->initialize($conf);
  			$data['pagination'] = 	$this->pagination->non_ajax();
			
			$data['info']		=	$res;
			$data['total']  	=   $res['total_num'];
			$this->load->view('search', $data);
		}
	
	
		#Show content of one of search results
		function detail($title = ""){
			$show = $this->search_model->get_detail_by_title($title);
			
			$data['detail']	=	$show;
			$this->load->view('detail', $data);
		}	
	
	}
	/*End of class*/